﻿using System;
using System.Collections.Generic;
using T.FAS.Runtime.Metadata.Entity.ScheduleJob;
using T.ServiceComponent.Database.Service;

namespace T.FAS.Runtime.ScheduleJob.Dao
{
    public class ScheduleJobLogic: IScheduleJobDao
    {
        IScheduleJobDao scheduleJobDao = DaoFactory.GetDaoFactory<IScheduleJobDao>().Instance;


        public List<Metadata.Entity.ScheduleJob.ScheduleJob> GetScheduleJobByFilter(Dictionary<string,string> filter)
        {
            return scheduleJobDao.GetScheduleJobByFilter(filter);
        }

        public Metadata.Entity.ScheduleJob.ScheduleJob GetScheduleJobByID(string sJobID)
        {
            return scheduleJobDao.GetScheduleJobByID(sJobID);
        }

        public void AddScheduleJob(Metadata.Entity.ScheduleJob.ScheduleJob sJob)
        {
            scheduleJobDao.AddScheduleJob(sJob);
        }

        public void UpdateScheduleJob(Metadata.Entity.ScheduleJob.ScheduleJob sJob)
        {
            scheduleJobDao.UpdateScheduleJob(sJob);
        }

        public void DeleteScheduleJob(string sJobID)
        {
            scheduleJobDao.DeleteScheduleJob(sJobID);
        }

        public int CheckUnique(Dictionary<string, string> filter)
        {
            return scheduleJobDao.CheckUnique(filter);
        }

        /// <summary>
        /// 保存或修改唯一性验证
        /// </summary>
        /// <param name="action">DB实体</param>
        /// <param name="OpeType">0:新增; 1:修改</param>
        /// <returns>true:表示入参action唯一，可以进行保存; false:表示数据库中存在重复数据，无法保存</returns>
        public bool CheckUnique(Metadata.Entity.ScheduleJob.ScheduleJob sJob, int OpeType = 0)
        {
            var filter = new Dictionary<string, string>
            {
                { "Code", sJob.Code },
            };
            if (OpeType == 1)
            {
                filter["ID"] = sJob.ID;
            }
            var cnt = scheduleJobDao.CheckUnique(filter);
            return cnt == 0;
        }
    }
}
